﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HostpitalManage.DAO
{
    class Connection
    {
        static SqlConnection connect = new SqlConnection("Data Source=SON;Initial Catalog=HospitalManagementSystem;Integrated Security=True");

        public SqlConnection conDB()
        {
            SqlConnection con = new SqlConnection("Data Source=SON;Initial Catalog=HospitalManagementSystem;Integrated Security=True");
            return con;
        }

        public bool checkLogin(String user , String password) {
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand("",connect);
            cmd.ExecuteNonQuery();
            int i = cmd.ExecuteNonQuery();
            return true;
        }

        public void AddEmployee(String id, String user , String password , String name , String address , int phone , DateTime birth , int gender , String job) {
            try
            {
                connect.Open();
                SqlCommand cmd = new SqlCommand("InsertEmployee", connect);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@MaNhanVien", id));
                cmd.Parameters.Add(new SqlParameter("@TenDangNhap", user));
                cmd.Parameters.Add(new SqlParameter("@MatKhau", password));
                cmd.Parameters.Add(new SqlParameter("@HoTen", name));
                cmd.Parameters.Add(new SqlParameter("@DiaChi", address));
                cmd.Parameters.Add(new SqlParameter("@SoDienThoai", phone));
                cmd.Parameters.Add(new SqlParameter("@NgaySinh", birth));
                cmd.Parameters.Add(new SqlParameter("@GioiTinh", gender));
                cmd.Parameters.Add(new SqlParameter("@ChucVu", job));
                cmd.ExecuteNonQuery();
                MessageBox.Show("Done!");
            }
            catch (Exception)
            {
                MessageBox.Show("Error!");
            }
            
        }

        public void AddPatient(String id , String name , DateTime birth , String address , int gender , int phone , String job) {
            connect.Open();
            try
            {
                SqlCommand cmd = new SqlCommand("InsertUser", connect);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@MaBenhNhan", id));
                cmd.Parameters.Add(new SqlParameter("@HoTen", name));
                cmd.Parameters.Add(new SqlParameter("@NgaySinh", birth));
                cmd.Parameters.Add(new SqlParameter("@DiaChi", address));
                cmd.Parameters.Add(new SqlParameter("@GioiTinh", gender));
                cmd.Parameters.Add(new SqlParameter("@SoDienThoai", phone));
                cmd.Parameters.Add(new SqlParameter("@NgheNghiep", job));
                cmd.ExecuteNonQuery();
                MessageBox.Show("Done!");
            }
            catch (Exception)
            {
                MessageBox.Show("Error!");
            }
            
        }
    }
}
